package com.myapi.client;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.persistence.Embedded;

import com.myapi.Hand;
import com.myapi.client.DAO.CardDAO;
import com.myapi.client.DAO.PlayerDAO;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class PlayerHandDAO implements Serializable{
	@PrimaryKey      
	   @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
	     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
		     private String cdId; 
	
		     private Key phId; 


	@Persistent
	Set<Key> keyCard;
	@Persistent(mappedBy="playerDAO")
	PlayerDAO playerDAO;
	@Persistent
	boolean mucked;
	@Persistent
	boolean allIn;
	@Persistent
	private ArrayList<CardDAO> cards;
	@Persistent
	double odds;
	@Persistent
	ArrayList<Double> raise;
	@Persistent
	ArrayList<Double> call;
	@Persistent
	double chipsDiff;

	public PlayerHandDAO(){
		cards=new ArrayList<CardDAO> ();
		keyCard=new HashSet<Key>();
		odds=0;
	}

	public PlayerDAO getPlayerInfo() {
		return playerDAO;
	}
	
	public void setPlayerInfo(PlayerDAO playerDAO) {
		this.playerDAO = playerDAO;
	}

	public boolean isMucked() {
		return mucked;
	}

	public void setMucked(boolean mucked) {
		this.mucked = mucked;
	}

	public ArrayList<CardDAO> getCards() {
		return cards;
	}

	public void setCards(ArrayList<CardDAO> cards) {
		this.cards = cards;
	}

	public double getOdds() {
		return odds;
	}

	public void setOdds(double odds) {
		this.odds = odds;
	}

	public ArrayList<Double> getRaise() {
		return raise;
	}

	public void setRaise(ArrayList<Double> raise) {
		this.raise = raise;
	}

	public ArrayList<Double> getCall() {
		return call;
	}

	public void setCall(ArrayList<Double> call) {
		this.call = call;
	}

	public double getChipsDiff() {
		return chipsDiff;
	}

	public void setChipsDiff(double chipsDiff) {
		this.chipsDiff = chipsDiff;
	}

	public boolean isAllIn() {
		return allIn;
	}

	public void setAllIn(boolean allIn) {
		this.allIn = allIn;
	}
	public void addCardKey(CardDAO card){
		keyCard.add(card.getKey());
		card.addtKeyPlayerHand(this);
	}

	public Key getKey() {
		// TODO Auto-generated method stub
		return phId;
	}

	public PlayerHandDAO copy(){
		ArrayList<Double> calltmp=new ArrayList<Double>();
		for(Double doubletpmp:call)
			calltmp.add(doubletpmp);

		
		ArrayList<Double> raisetmp=new ArrayList<Double>();
		for(Double doubletpmp:raise)
			raisetmp.add(doubletpmp);
		
		ArrayList<CardDAO> cardList=new ArrayList<CardDAO>();
		for(CardDAO cardpmp:cards){
			 cardList.add(cardpmp);
		}
		
		setAllIn(allIn);
		setCall(calltmp);
		setRaise(raisetmp);
		setCards(cardList);
		
		return this;
	}
}
